package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.entity.vo.UserInfoSearchVO;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.User;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */
@RestController
//@CrossOrigin
@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {

    @Resource
    UserInfoService userInfoService;


    @ApiOperation("条件分页查询")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResponseVo list(UserInfoSearchVO userInfoSearchVO,
                           @PathVariable("pageNum")Integer pageNum,
                           @PathVariable("pageSize")Integer pageSize){
        Page<UserInfo> page = new Page<>(pageNum,pageSize);
        userInfoService.getUserInfos(userInfoSearchVO,page);
        return ResponseVo.ok().data("page",page);

    }


    @ApiOperation("锁定/解锁会员")
    @PutMapping("/{userId}/{status}")
    public ResponseVo updateUserStatus(@PathVariable("userId")Long userId,
                                       @PathVariable("status")Integer status){

        UserInfo userInfo = new UserInfo();
        userInfo.setId(userId);
        userInfo.setStatus(status);
        userInfoService.updateById(userInfo);

        return ResponseVo.ok().message(status==0?"锁定成功":"解锁成功");

    }
}

